package com.intellagric.controller.module.sys_area;

import com.intellagric.common.pojo.LayuiDataGridResult;
import com.intellagric.common.pojo.ResponseMessage;
import com.intellagric.pojo.SysArea;
import com.intellagric.service.module.sys_area.AreaService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.Date;
import java.util.List;
import java.util.UUID;

/**
 * @Author: zhy
 * @email: 1269679946@qq.com
 * @Date: 2018/10/30
 * @DESC： 区域位置信息管理
 */
@Controller
public class AreaController {

    @Autowired
    private AreaService areaService;

    /**
     * 添加区域位置信息
     * @Param
     * @return ResponseMessage
     */
    @RequestMapping("/area/add")
    @ResponseBody
    public ResponseMessage add(SysArea area) {
        //初始信息
        area.setId(UUID.randomUUID().toString().replaceAll("-",""));
        area.setCreateDate(new Date());
        area.setUpdateDate(new Date());
        return areaService.addArea(area);
    }

    /**
     * 删除区域位置信息
     * @Param id
     * @return ResponseMessage
     */
    @RequestMapping("/area/delete")
    @ResponseBody
    public ResponseMessage delete(String id) {
        return areaService.deleteArea(id);
    }

    /**
     * 修改区域位置信息
     * @Param area
     * @return ResponseMessage
     */
    @RequestMapping("/area/edit")
    @ResponseBody
    public ResponseMessage edit(SysArea area) {
        area.setUpdateDate(new Date());
        area.setCreateDate(null);
        return areaService.editArea(area);
    }

    /**
     * 查询区域位置信息
     * @return SysArea
     */
    @RequestMapping("/area/{id}")
    @ResponseBody
    public SysArea get(@PathVariable String id) {
        return areaService.getAreaById(id);
    }

    /**
     * 查询区域位置信息列表
     * @return LayuiDataGridResult
     */
    @RequestMapping("/area/list")
    @ResponseBody
    public LayuiDataGridResult getList() {
        return areaService.getAreaList();
    }

    /**
     * 分页查询区域位置信息列表
     * @return LayuiDataGridResult
     */
    @RequestMapping("/area/page")
    @ResponseBody
    public LayuiDataGridResult getPage(int page,int rows) {
        return areaService.getAreaPage(page,rows);
    }

    /**
     * 查询区域位置信息树
     * @return LayuiDataGridResult
     */
    @RequestMapping("/area/tree")
    @ResponseBody
    public LayuiDataGridResult getTree() {
        return areaService.getAreaTree();
    }

    /**
     * 查询区域位置信息树
     * @return LayuiDataGridResult
     */
    @RequestMapping("/area/tree/select")
    @ResponseBody
    public List<SysArea> getTreeSelect() {
        return areaService.getAreaTree().getData();
    }
}
